const commander = require("commander");

// 导入仓库地址
const { vueRepo } = require("../config/repo-config");

//node自带的工具库util 其中有让模块支持promise的的函数类 promisify
const { promisify } = require("util");
const download = promisify(require("download-git-repo"));

//导入封装好的执行命令的函数 npm install  run serve之类的
const { commandSpawn } = require("../utils/terminal");

const createAction = async (project) => {
  console.log("lwt 正在死命创建vue项目");

  // 1. clone 项目 把git项目的内容下载下来 用到一个库 download-git-repo
  await download(vueRepo, project, { clone: true });

  // 2. 执行 npm install
  const command = process.platform === "win32" ? "npm.cmd" : "npm";
  await commandSpawn(command, ["install"], { cwd: `./${project}` });

  // 3. 执行 npm run serve
  commandSpawn(command, ["run", "serve"], { cwd: `./${project}` });

  
};
module.exports = {
  createAction,
};
